<template>
  <div class="detail_box">
    <div class="operate_box">
      <div class="item_box">
        <div class="operate_item">
          <label>关键词：</label>
          <el-input type="text" placeholder="请输入关键词" v-model="keyword"></el-input>
        </div>
        <div class="operate_item">
          <span class="operate_btn search_btn" @click="getTableInfo(1)">查询</span>
          <span class="operate_btn reset_btn" @click="resetTable">重置</span>
        </div>
      </div>
    </div>
    <div class="table_box">
      <el-table
        border
        v-loading="loading"
        :header-cell-style="tableHeader"
        ref="multipleTable"
        :data="tableInfo"
        tooltip-effect="dark"
        style="width: 100%;">
        <el-table-column
          width="85"
          prop="id"
          label="ID">
        </el-table-column>
        <el-table-column
          prop="modifyTime"
          sortable
          label="修改时间">
          <template slot-scope="scope">
            <span>{{ formatTime(scope.row.modifyTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="通知内容">
        </el-table-column>
        <el-table-column
          label="消息类型">
          <template slot-scope="scope">
            <span>{{ scope.row.type === 1 ? '短信' : '语音' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="管理人员">
          <template slot-scope="scope">
            <span>{{ scope.row.managerName ? scope.row.managerName : '——' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="联系方式">
          <template slot-scope="scope">
            <span>{{ scope.row.phone ? scope.row.phone : '——' }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="record_page">
      <span class="page_count">共<i>{{ totals }}</i>条</span>
      <el-pagination
        @size-change="sizeChange"
        @current-change="getTableInfo"
        background
        :current-page="currentPage"
        :page-sizes="[15, 20, 30, 40]"
        :page-size="pageSize"
        layout="prev, pager, next, sizes,jumper"
        :total="totals">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import commons from "@/utils/common";
import {getBtn} from "@/utils/btnAuth";
import {getFireMessage} from "../../../api/notice";

export default {
  data() {
    return {
      keyword: '',
      tableInfo: [],
      currentPage: 1,
      pageSize: 15,
      totals: 0,
      loading: false,
      btn: {}
    }
  },
  mounted() {
    getBtn().then(res => {
      this.btn = res;
      if (this.btn.query) {
        this.getTableInfo(1);
      }
    })
  },
  methods: {
    // 获取列表信息
    getTableInfo(page) {
      let that = this;
      that.loading = true;
      that.currentPage = page;
      let queryParams = {
        limit: that.pageSize,
        page: page,
        keyword: that.keyword
      }
      getFireMessage(queryParams).then(res => {
        that.tableInfo = res.data ? res.data.list : [];
        that.totals = res.data ? res.data.count : 0;
        that.loading = false;
      }, (err) => {
        that.loading = false;
      });
    },

    resetTable() {
      this.keyword = '';
      this.pageSize = 15;
      this.getTableInfo(1);
    },

    sizeChange(val) {
      this.pageSize = val;
      this.getTableInfo(1)
    },

    formatTime(time) {
      return commons.formatTime(time);
    },

    // 设置table标题居中
    tableHeader({row, column, rowIndex, columnIndex}) {
      return 'background:#F0F2F5;color:#111;padding:10px 0;font-size:14px;font-weight:600'
    },
  }
}
</script>

<style scoped>

</style>
